<!--
 * @Description: 三天 五天 七天（传入）切换
 * @Autor: xinsang
 * @Date: 2020-11-13 15:34:49
 * @LastEditors: zhangqj
 * @LastEditTime: 2021-03-13 11:03:06
-->
<template>
  <!-- 选时间 start -->
  <div class="timetabs">
    <span
      v-for="(item, ind) in timeList"
      :key="ind"
      :class="tabindex === ind ? 'activetab' : ''"
      @click="tabClick(item, ind)"
    >{{ item.label }}</span>
  </div>
  <!-- <span
      v-for="(item, index) in timeList"
      :id="`item${index}`"
      :key="index"
      :style="
        tabindex === index
          ? `color:#fff;background:${activeColor};border: 1px solid ${activeColor};`
          : ''
      "
      @click="tabClick(item, index)"
      @mouseover="hover = { bool: true, index }"
      @mouseleave="hover = { bool: false, index }"
      >{{ item.label }}</span
    > -->
  <!-- </div> -->
</template>

<script>
export default {
  name: 'TimeTabs',
  props: {
    tabindex: {
      type: Number,
      default: 0
    },
    timeList: {
      type: Array,
      default() {
        return []
      }
    },
    activeColor: {
      type: String,
      default: '#ff8147'
    }
  },
  data() {
    return {
      hover: false
    }
  },
  //   watch: {
  //     hover: {
  //       handler (val) {
  //         let item = document.getElementById(`item${val.index}`)
  //         if (val.index === this.tabindex) return
  //         if (val.bool) {
  //           item.setAttribute('style', `color:${this.activeColor}`)
  //         } else {
  //           item.setAttribute('style', 'color:#666')
  //         }
  //       }
  //     }
  //   },
  methods: {
    // 时间选择
    tabClick(item, index) {
      this.$emit('tabClick', item, index)
    }
  }
}
</script>

<style lang="scss" scoped>
.timetabs {
  position: absolute;
  left: 282px;
  top: 77px;
  z-index: 99;
  span {
    display: inline-block;
    color: #999999;
    width: 28px;
    height: 16px;
    font-size: 12px;
    line-height: 16px;
    text-align: center;
    margin: 0 10px;
    cursor: pointer;
    position: relative;
    &:hover {
      color: #ff0929;
    }
  }
  .activetab {
    color: #ff0929;
    &::before {
      content: '';
      width: 16px;
      height: 1px;
      background: #ff0929;
      border-radius: 1px;
      position: absolute;
      bottom: -2px;
      left: 6px;
    }
  }
}
</style>
